package io.terminus.spzx.manager.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.terminus.spzx.manager.service.SysRoleMenuService;
import io.terminus.spzx.model.dto.system.AssignMenuDto;
import io.terminus.spzx.model.vo.common.Result;
import io.terminus.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 系统角色与菜单绑定Controller
 * @Date 2024-09-03
 */
@RestController
@Tag(name = "系统角色与菜单绑定接口")
@RequestMapping(value = "/admin/system/roleMenu")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /**
     * 根据角色ID查询绑定的菜单ID列表
     *
     * @param roleId 角色ID
     * @return 菜单列表
     */
    @GetMapping("/findSysRoleMenuByRoleId/{roleId}")
    public Result<Map<String, Object>> findSysRoleMenuByRoleId(@PathVariable("roleId") Long roleId) {
        Map<String, Object> roleMenuMap = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);

        return Result.build(roleMenuMap, ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存角色分配的菜单
     *
     * @param assignMenuDto 角色分配的菜单
     * @return 保存结果
     */
    @PostMapping("/doAssign")
    public Result<Void> doAssign(@RequestBody AssignMenuDto assignMenuDto) {
        sysRoleMenuService.doAssign(assignMenuDto);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
